import React, {Component} from 'react';
import Table from '../Public/Table';
import {NavLink} from "react-router-dom";

class OrderIndexTable extends Component {
	constructor(props) {
		super(props);
		this.state = {
			columns: [
				{
					title: '订单号',
					render: data => <NavLink to={'/order/detail/' + data.orderNo}>
						{data.orderNo}
					</NavLink>
				},
				{
					title: '收件人',
					props: 'receiverName'
				},
				{
					title: '订单状态',
					props: 'statusDesc'
				},
				{
					title: '订单总价',
					props: 'payment'
				},
				{
					title: '创建时间',
					render: data => <span>{this.formatDate(data.createTime)}</span>
				},
				{
					title: '操作',
					render: data => <NavLink to={'/order/detail/' + data.orderNo}>
						查看
					</NavLink>
				}
			]
		}
	}

	formatDate(value) {
		let date = new Date(value);
		return date.toLocaleString();
	}

	render() {
		return (
			<div>
				<Table
					columns={this.state.columns}
					data={this.props.data}
					keyProps="orderNo"
					emptyInfo="没有找到相应的结果~"
				/>
			</div>
		);
	}
}

export default OrderIndexTable;